package model

import (
	"poker/db"

	"go.mongodb.org/mongo-driver/bson"
)

type User struct {
	Uid        string `json:"uid" bson:"_id" binding:"required"`
	Data       string `json:"data" bson:"data" binding:"required"`
	Auth       string `json:"auth" bson:"-" binding:"required"`
	UpdateDate string `bson:"update_date"`
	AppID      string `bson:"appid"`
}

type VoteDate struct {
	Uid      string  `json:"uid" bson:"_id" binding:"required"`
	NickName string  `json:"nickname" bson:"nickname" binding:"required"`
	HeadUrl  string  `json:"head_url" bson:"head_url"`
	Score    int64   `json:"score" bson:"score"`
	GID      string  `json:"gid" bson:"-"`
	Number   int64   `json:"number" bson:"-"`
	Voters   []Girl2 `json:"voters" bson:"voters"`
	Auth     string  `json:"auth" bson:"-" binding:"required"`
	AppID    string  `json:"appid" bson:"appid"`
}

type VoteResp struct {
	Uid      string  `json:"uid" bson:"_id" binding:"required"`
	NickName string  `json:"nickname" bson:"nickname" binding:"required"`
	HeadUrl  string  `json:"head_url" bson:"head_url"`
	Score    int64   `json:"score" bson:"score"`
	Voters   []Girl2 `json:"voters" bson:"voters"`
	AppID    string  `json:"appid" bson:"appid"`
}

func (u *User) Save(col string, filter interface{}) error {
	update := bson.M{"$set": bson.M{"data": u.Data, "appid": u.AppID, "update_date": u.UpdateDate}}
	return db.UpdateOne(col, filter, update)
}

func (u *User) FindOne(col string, filter interface{}) error {
	return db.FindOne(col, filter, u)
}
